package o;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appmarket.support.account.HeadInfoReceiver;
import com.huawei.cloudservice.CloudAccount;
import com.huawei.hwid.core.datatype.UserInfo;
import com.huawei.hwid.core.helper.handler.ErrorStatus;
import o.epx.d;

public class eox {
    private static HeadInfoReceiver ॱ = new HeadInfoReceiver();

    static class c extends ccs {
        private boolean ˋ;

        public c(boolean z) {
            this.ˋ = z;
        }

        public void onFinish(Bundle bundle) {
            boolean z = false;
            if (bundle == null) {
                Logger.ˋ("UserInfoGetter", "UserInfoRequestHandler onFinish bundle is null");
                eqq.ˋ().ˋ(203);
            } else if (UserSession.getInstance().isLoginSuccessful()) {
                UserInfo userInfo = (UserInfo) bundle.getParcelable("userInfo");
                if (userInfo == null) {
                    Logger.ˋ("UserInfoGetter", "UserInfoRequestHandler onFinish userInfo is null");
                    eqq.ˋ().ˋ(203);
                    return;
                }
                UserSession.getInstance().setUserName(userInfo.getLoginUserName());
                UserSession.getInstance().setNickname(userInfo.getNickName());
                String serviceCountryCode = userInfo.getServiceCountryCode();
                Logger.ˎ("UserInfoGetter", "UserInfoRequestHandler onFinish homeCountry=" + serviceCountryCode);
                if (dof.ˋ(serviceCountryCode)) {
                    Logger.ˎ("UserInfoGetter", " UserInfoHandler onFinish homeCountry is blank");
                } else if (this.ˋ) {
                    UserSession.getInstance().setHomeCountryTimestamp(serviceCountryCode);
                    Logger.ˎ("UserInfoGetter", "UserInfoRequestHandler onFinish isFromStartup=" + this.ˋ);
                } else {
                    String ॱ = eqp.ॱ();
                    UserSession.getInstance().setHomeCountryTimestamp(serviceCountryCode);
                    if (!serviceCountryCode.equalsIgnoreCase(ॱ)) {
                        z = true;
                    }
                    Logger.ˎ("UserInfoGetter", " UserInfoHandler onFinish homeCountry=" + serviceCountryCode + " lastHomeCountry=" + ॱ + " isChanged=" + z);
                }
                if (!(UserSession.getInstance().getStatus() == 5 || TextUtils.isEmpty(UserSession.getInstance().getHomeCountry()))) {
                    eoy.ˎ(ContentManager.getInstant().getContext(), this.ˋ);
                }
                serviceCountryCode = dof.ʼ(userInfo.getHeadPictureUrl());
                Logger.ˎ("UserInfoGetter", "UserInfoRequestHandler finished.");
                if (dof.ˋ(serviceCountryCode)) {
                    Logger.ˎ("UserInfoGetter", "UserInfoRequestHandler getHeadPicture is blank");
                }
                UserSession.getInstance().setHeadUrl(serviceCountryCode);
                eua.ˏ().ʼ("st_error_retry_cancel");
                eqi.ˏ().ˎ(userInfo.getBirthDate());
                eop.ˎ(UserSession.getInstance());
                eox.ॱ();
                if (z) {
                    eqq.ˋ().ˋ(201);
                } else {
                    eqq.ˋ().ˋ(202);
                }
            } else {
                Logger.ˋ("UserInfoGetter", "Account has been logout");
            }
        }

        public void onError(ErrorStatus errorStatus) {
            Logger.ˋ("UserInfoGetter", "UserInfoRequestHandler onError = " + errorStatus.getErrorCode() + " , msg=" + errorStatus.getErrorReason());
            super.onError(errorStatus);
            if (errorStatus.getErrorCode() == 4099 || errorStatus.getErrorCode() == 70002016) {
                eod.ᐝ(ContentManager.getInstant().getContext());
                return;
            }
            if (UserSession.getInstance().getStatus() == 4) {
                UserSession.getInstance().setStatus(1);
            }
            eqq.ˋ().ˋ(203);
        }

        protected String ˋ() {
            return "getUserInfo";
        }
    }

    public static void ˏ() {
        ActivityUtil.unregisterReceiver(ContentManager.getInstant().getContext(), ॱ);
    }

    public static void ˋ() {
        Context ˋ = ContentManager.getInstant().getContext();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.hwid.ACTION_HEAD_PIC_CHANGE");
        ActivityUtil.registerReceiver(ˋ, intentFilter, ॱ);
    }

    public static void ˎ(Context context, boolean z) {
        CloudAccount ˊ = eos.ˊ();
        if (ˊ == null) {
            Logger.e("UserInfoGetter", "CloudAccount of current is null , getUserInfo failed");
            eqq.ˋ().ˋ(203);
            return;
        }
        Logger.ˎ("UserInfoGetter", "CloudAccount is not null , getUserInfo starting");
        ˊ.getUserInfo(context, "1000", new c(z));
    }

    public static void ॱ() {
        ll.ˏ(ContentManager.getInstant().getContext()).ˋ(new Intent(d.ˎ));
    }
}
